﻿using System;
using CzfSDK;
using System.Collections;
using System.Collections.Generic;

namespace Server
{
	public class GameProto : CzfProto
	{
		public static GameProto current;
		public GameProto (int zipLv = 0) : base(zipLv)
		{
			current = this;
			this.defaultMethod = "FrameSync";
		}

		// 心跳包
		public Hashtable Heart()
		{
			var ret = new Hashtable ();
			return ret;
		}

		#region 账号
		/// <summary>
		/// 登陆或注册
		/// </summary>
		/// <returns>The login.</returns>
		/// <param name="name">Name.</param>
		/// <param name="password">Password.</param>
		public Hashtable MLogin(string account, string password)
		{
			var ret = UserManager.Login (account, password, client);
			return ret;
		}

		// 注册账号
		public Hashtable Create(string account, string name, string password)
		{
			return UserManager.CreateUser (account, name, password, client);
		}

		// 更新玩家的新手步骤
		public string SetGuide(int guide)
		{
			var user = User.Get (CzfProto.client);
			return UserManager.SetGuide (user.id, guide);
		}
		#endregion

		#region 阵容相关
		// 创建阵容
//		public static Hashtable CreateFormation(string name, string skillIds, int roleId)
//		{
//			var user = User.Get (CzfProto.client);
//			int id = FormationManager.CreateFormation (user.id, name, skillIds, roleId);
//			var ht = new Hashtable ();
//			ht ["id"] = id;
//			ht ["list"] = FormationManager.GetAllFormation (user.id);
//			return ht;
//		}

		// 获取玩家的全部阵容
		public static List<Hashtable> GetAllFormation()
		{
			var user = User.Get (CzfProto.client);
			return FormationManager.GetAllFormation (user.id);
		}

		// 修改阵容
		public static Hashtable UpdateFormation(int formationId, string skillIds, int roleId)
		{
			var user = User.Get (client);
			FormationManager.UpdateFormation (formationId, user.id, skillIds, roleId);
			return FormationManager.Get (formationId);
		}

		// 修改阵容名字
//		public static Hashtable UpdateFormationName(int formationId, string name)
//		{
//			var user = User.Get (CzfProto.client);
//			FormationManager.UpdateFormationName (formationId, user.id, name);
//			return FormationManager.Get (formationId);
//		}

		// 删除阵容
//		public static string DeleteFormation(int formationId)
//		{
//			var user = User.Get (CzfProto.client);
//			return FormationManager.DeleteFormation (formationId, user.id);
//		}

		// 修改当前阵容
		public static string ChangeNowFormation(int formationId)
		{
			var user = User.Get (CzfProto.client);
			return FormationManager.ChangeNowFormation (formationId, user.id);
		}
		#endregion

		#region 角色相关
		// 获取玩家有的所有角色id
		public List<int> GetAllRoleIds()
		{
			var user = User.Get (CzfProto.client);
			return RoleManager.GetRoleIds (user.id);
		}

		// 购买角色
		public static string BuyRole(int roleId)
		{
			var user = User.Get (CzfProto.client);
			return RoleManager.BuyRole (user.id, roleId);
		}
		#endregion

		#region 技能相关
		// 碎片兑换技能
		public string AddSkillByDust(int skillId)
		{
			var user = User.Get (CzfProto.client);
			return SkillManager.AddSkillByDust (user.id, skillId);
		}

		// 获取玩家有的所有技能id
		public List<int> GetAllSkillIds()
		{
			var user = User.Get (CzfProto.client);
			return SkillManager.GetSkillIds (user.id);
		}

		// 获取玩家有的所有技能短id
		public List<int> GetAllSkillShortIds()
		{
			var user = User.Get (CzfProto.client);
			return SkillManager.GetSkillShortIds (user.id);
		}
		#endregion

		#region 战斗相关
		// 收到帧同步数据
		public void FrameSync(Hashtable ht)
		{
			var user = User.Get (CzfProto.client);
			if (user != null && user.room != null) {
				user.room.ReceiveFrameSyncData (user, ht);
			}
		}

		// 有角色死亡
		public void UserDie(int userId)
		{
			var user = User.Get (CzfProto.client);
			if (user != null && user.room != null) {
				user.room.UserDie (userId);
			}
		}

		// 有角色死亡
		public void TaDie(int userId)
		{
			var user = User.Get (CzfProto.client);
			if (user != null && user.room != null) {
				user.room.TaDie (userId);
			}
		}
		#endregion

		#region 等待房间
		// 提交加载进度
		public Hashtable ReadyProgress(int progress)
		{
			var user = User.Get (CzfProto.client);
			if (user != null && user.room != null) {
				return user.room.ReadyProgress (user.id, progress);
			}

			return null;
		}

		public string WaitRoom(string type)
		{
			CzfLog.Info ("WaitRoom");
			var user = User.Get (CzfProto.client);
			return RoomManager.WaitRoom(user, type);
		}

		public string StopWaitRoom(string type)
		{
			CzfLog.Info ("StopWaitRoom");
			var user = User.Get (CzfProto.client);
			return RoomManager.StopWaitRoom(user, type);
		}
        #endregion

        #region 好友相关
        public static List<Hashtable> GetTopSingle()
        {
            return FriendManager.GetSingle();
        }

        public static List<Hashtable> GetTopFull()
        {
            return FriendManager.GetFull();
        }

        public static List<Hashtable> GetAllFriends()
        {
            var user = User.Get(CzfProto.client);
            return FriendManager.GetAllFriends(user.id);
        }

        public static List<Hashtable> GetAllApplyFriends()
        {
            var user = User.Get(CzfProto.client);
            return FriendManager.GetAllApplyFriends(user.id);
        }

        public static string ApplyFriend(int friendId)
        {
            var user = User.Get(CzfProto.client);
            return FriendManager.ApplyFriend(user.id, friendId);
        }

        public static string AgreeFriend(int friendId)
        {
            var user = User.Get(CzfProto.client);
            return FriendManager.AgreeFriend(user.id, friendId);
        }

        public static string RefuseFriend(int friendId)
        {
            var user = User.Get(CzfProto.client);
            return FriendManager.RefuseFriend(user.id, friendId);
        }

        public static string DeleteFriend(int friendId)
        {
            var user = User.Get(CzfProto.client);
            return FriendManager.DeleteFriend(user.id, friendId);
        }
        #endregion

		#region 邮件
		// 获取玩家的邮件列表
		public static List<Hashtable> GetAllMail()
		{
			var user = User.Get (CzfProto.client);
			return MailManager.GetAllMail (user.id);
		}

		// 将邮件标记已读
		public static void SetReadType(int mailId)
		{
			var user = User.Get (CzfProto.client);
			MailManager.SetReadType (user.id, mailId);
		}

		// 领取邮件附件
		public static string GetMailPrize(int mailId)
		{
			var user = User.Get (CzfProto.client);
			return MailManager.GetMailPrize (user.id, mailId);
		}
		#endregion

		#region 商城
		// 获取商城列表
		public List<Hashtable> GetAllShop()
		{
			var user = User.Get (CzfProto.client);
			return ShopManager.GetAllShop (user.id);
		}

		// 购买商城道具
		public string BuyShopItem(int shopId)
		{
			var user = User.Get (CzfProto.client);
			return ShopManager.BuyShopItem (user.id, shopId);
		}
		#endregion

		#region 地图
		// 读取地图格子列表
		public List<Hashtable> GetAllMapCell()
		{
			return MapManager.GetAllMapCell ();
		}

		// 读取地图信息
		public List<Hashtable> GetAllMap()
		{
			return MapManager.GetAllMap ();
		}

		// 提交地图信息
		public string CreateMap(string name, string info)
		{
			return MapManager.CreateMap (name, info);
		}
		#endregion

		// 获取配置信息
		public Hashtable GetAllConfigs()
		{
			var ht = new Hashtable ();
			ht ["arenaTemplate"] = MConfig.GetArenaTemplate ();
			ht ["itemTemplate"] = MConfig.GetItemTemplate ();
			ht ["skillTemplate"] = MConfig.GetSkillTemplate ();
			ht ["skillAffix"] = MConfig.GetSkillAffix ();
			ht ["skillArrow"] = MConfig.GetSkillArrow ();
			ht ["skillServant"] = MConfig.GetSkillServant ();
			ht ["roleTemplate"] = MConfig.GetRoleTemplate ();
			ht ["gamepara"] = MConfig.GetGameConfigHt ();
			return ht;
		}
	}
}

